package com.xneure.utils;

import java.lang.management.ManagementFactory;
import java.util.Properties;

public class SystemUtil{
	enum SysParam{
		jVer("Java版本","java.version"),
		jVen("运行环境","java.vendor"),
		jHome("安装路径","java.home"),
		jClsVer("类格式版本号","java.class.version"),
		jExtDir("扩展目录的路径","java.ext.dirs"),
		osName("系统名称","os.name"),
		osArch("系统构架","os.arch"),
		osVer("系统版本","os.version"),
		userDir("当前工作目录","user.dir"),;
		private String param;
		private String title;

		SysParam(String title,String param){
			this.title = title;
			this.param = param;
		}

		public String getParam(){
			return param;
		}

		public String getTitle(){
			return title;
		}
	}

	public static String getSystemInfo(){
		Properties props = System.getProperties();
		StringBuilder sb = new StringBuilder();
		for(SysParam sp:SysParam.values()){
			sb.append(sp.title).append("：").append(props.get(sp.param)).append("\r\n");
		}
		return sb.toString();
	}

	public static String getTempDir(){
		return getParameter("java.io.tmpdir");
	}

	public static String getParameter(String param){
		return System.getProperty(param);
	}

	public static String getJVM_ID(){
		String pid = ManagementFactory.getRuntimeMXBean().getName();
		int indexOf = pid.indexOf('@');
		if(indexOf > 0){
			pid = pid.substring(0,indexOf);
		}
		return pid;
	}
}
